$(function(){
	if (top != window) {
		top.location.href = window.location.href;
	}
	$("#username,#password").keydown(function(e){
		
		if(!e){
	        e=window.event;
	    }
	    if((e.keyCode||e.which)===13){
	    	checkUserForm();
	    }
	});
	
	$("#login_in").click(function(){
		checkUserForm();
	});
	
	function checkUserForm() {
		var userName = $("#username").val();
		var userPassword = $("#password").val();
		if (userName == "" || userPassword == "") {
			bootbox.alert("用户名或密码不能为空");
			return false;
		}
		var b;
		$.ajax({
			type : "POST",
			url  : $("#ctx").val()+"/loginCheck.html?data="+ new Date(),
			data : {
				username : userName,
				password : userPassword
			},
			dataType: "json",
			async : false,
			success : function(data) {
				if (data.error == "0") {
					b = false;
				} else {
					b = true;
					alert(data.error);
				}
			}
		});
		if (b) {
			return true;
		}
		
		$("#loginForm").submit();
		
	}
	
	
});